package svc

import (
	"github.com/zeromicro/go-zero/rest"
	"github.com/zeromicro/go-zero/zrpc"
	"shopping-mall/shoppingapi/internal/config"
	"shopping-mall/shoppingapi/internal/middleware"
	"shopping-mall/shoppingrpc/shoppingrpc"
	"shopping-mall/shoppingrpc/shoppingrpcclient"
)

type ServiceContext struct {
	Config              config.Config
	ShoppingRpc         shoppingrpc.ShoppingrpcClient
	UserAgentMiddleware rest.Middleware
}

func NewServiceContext(c config.Config) *ServiceContext {
	return &ServiceContext{
		Config:              c,
		ShoppingRpc:         shoppingrpcclient.NewShoppingrpc(zrpc.MustNewClient(c.ShoppingRpc)),
		UserAgentMiddleware: middleware.NewUserAgentMiddleware().Handle,
	}
}
